package com.woniuxy.controller;

import com.woniuxy.service.impl.UserGoodsServiceImpl;
import com.woniuxy.util.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/usergoods")
public class UserGoodsController {
    @Resource
    private UserGoodsServiceImpl userGoodsService;

    @GetMapping("/saveHistory/{userId}/{goodsKey}")
    private ResponseData saveHistory(@PathVariable("userId") Integer userId,
                                     @PathVariable("goodsKey") String goodsKey) { //按照用户信息存储搜索历史记录到Redis
        userGoodsService.saveHistorySearchByUser(goodsKey, userId);
        return ResponseData.success(null);
    }

    @GetMapping("/findHistory/{userId}")
    private ResponseData findHistory(@PathVariable("userId") Integer userId) { //按照用户信息从Redis查找其搜索历史记录
        List<String> history = userGoodsService.findHistorySearchByUser(userId);
        return ResponseData.success(history);
    }
}
